package com.szalay.desktopsearch.ui;

import com.szalay.desktopsearch.indexer.Indexer;
import com.szalay.desktopsearch.search.Search;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;

/**
 * The main window.
 */
public class MainWindow extends JFrame {
    private static final long serialVersionUID = -6290829079323810317L;
    /**
     * Create new main window.
     * @param search 
     */
    public MainWindow(final Search search, final Indexer indexer) throws Exception {
        setTitle("DesktopSearch");
        setIconImage(new ImageIcon(MainWindow.class.getResource("/icons/search.png")).getImage());
        
        //window listener to exit the app
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                if (JOptionPane.showConfirmDialog(null, "Quit application?", "DesktopSearch", JOptionPane.YES_NO_OPTION)
                        == JOptionPane.YES_OPTION) {
                    System.exit(0);
                }
            }
        });
        
        //add tabs
        final JTabbedPane tabPane = new JTabbedPane();
        tabPane.add("Search", new SearchPanel(search));
        tabPane.add("Statistics", new StatisticsPanel(indexer));
        tabPane.add("About", new AboutPanel());
        add(tabPane);
    
        //size and show
        setSize(1000, 800);
        UI.centerScreen(this);
        setVisible(true);
    }
}
